import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { PersonInfoApi } from '#/api/cmt/person/info';

import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';

import { z } from '#/adapter/form';
import { getRangePickerDefaultProps } from '#/utils';

export const GENDER_OPTIONS = [{ label: '未知', value: 0 }, { label: '男', value: 1 }, { label: '女', value: 2 }];
export const PERSON_TYPE_OPTIONS = [{ label: '普通居民', value: 1 }, { label: '志愿者', value: 2 }, { label: '师资', value: 3 }, { label: '社区干部', value: 4 }];
export const VOLUNTEER_LEVEL_OPTIONS = [{ label: '非志愿者', value: 0 }, { label: '一星', value: 1 }, { label: '二星', value: 2 }, { label: '三星', value: 3 }, { label: '四星', value: 4 }, { label: '五星', value: 5 }];

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'realName',
      label: '真实姓名',
      rules: 'required',
      component: 'Input',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请输入真实姓名',
      },
    },
    {
      fieldName: 'idCard',
      label: '身份证号',
      component: 'Input',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请输入身份证号',
      },
    },
    {
      fieldName: 'phone',
      label: '手机号',
      rules: 'required',
      component: 'Input',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请输入手机号',
      },
    },
    {
      fieldName: 'gender',
      label: '性别',
      component: 'RadioGroup',
      formItemClass: 'col-span-1',
      componentProps: {
        options: GENDER_OPTIONS,
      },
    },
    {
      fieldName: 'birthday',
      label: '生日',
      component: 'DatePicker',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请选择生日',
      },
    },
    {
      fieldName: 'age',
      label: '年龄',
      component: 'InputNumber',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请输入{field_label}', controlsPosition: 'right', class: '!w-full',
      },
    },
    {
      fieldName: 'education',
      label: '学历',
      component: 'Input',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请输入学历',
      },
    },
    {
      fieldName: 'occupation',
      label: '职业',
      component: 'Input',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请输入职业',
      },
    },
    {
      fieldName: 'address',
      label: '地址',
      component: 'Input',
      formItemClass: 'col-span-1',
      componentProps: {
        placeholder: '请输入地址',
      },
    },
    {
      fieldName: 'avatar',
      label: '头像',
      component: 'ImageUpload',
      formItemClass: 'col-span-1',
    },
    {
      fieldName: 'personType',
      label: '人员类型',
      component: 'Select',
      formItemClass: 'col-span-1',
      componentProps: {
        options: PERSON_TYPE_OPTIONS,
        placeholder: '请选择人员类型',
      },
    },
    {
      fieldName: 'volunteerLevel',
      label: '志愿者等级',
      component: 'Select',
      formItemClass: 'col-span-1',
      componentProps: {
        options: VOLUNTEER_LEVEL_OPTIONS,
        placeholder: '请选择志愿者等级',
      },
    },
    {
      fieldName: 'status',
      label: '状态',
      component: 'RadioGroup',
      formItemClass: 'col-span-1',
      componentProps: {
        options: getDictOptions(DICT_TYPE.COMMON_STATUS, 'number'),
      },
    },
    {
      fieldName: 'remark',
      label: '备注',
      component: 'Input',
      formItemClass: 'col-span-1',
      componentProps: {
        type: 'textarea',
        rows: 2,
        placeholder: '请输入备注',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        clearable: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<PersonInfoApi.PersonInfo>['columns'] {
  return [
    { type: 'checkbox', width: 40 },
    {
      field: 'id',
      title: 'ID',
      minWidth: 120,
    },
    {
      field: 'realName',
      title: '真实姓名',
      minWidth: 120,
    },
    {
      field: 'phone',
      title: '手机号',
      minWidth: 120,
    },
    {
      field: 'gender',
      title: '性别',
      minWidth: 120,
    },
    {
      field: 'age',
      title: '年龄',
      minWidth: 120,
    },
    {
      field: 'personType',
      title: '人员类型',
      minWidth: 120,
    },
    {
      field: 'volunteerLevel',
      title: '志愿者等级',
      minWidth: 120,
    },
    {
      field: 'status',
      title: '状态',
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
